@extends('default.layouts.vice_head_foot')
@section('title'){{Site::get('area_name').'招聘会|校园招聘会|人才市场招聘会信息|'.Site::get('webname')}} @endsection
{{--首页css--}}
@section('insert_css')
    <link rel="stylesheet" href="{{asset('/default/css/index/vice_public.css')}}">
    <link rel="stylesheet" href="{{asset('/default/css/index/jobFair.css')}}">
    <link rel="stylesheet" href="{{asset('/default/css/index/station.css')}}">

@endsection
{{--主体内容--}}
@section('content')
    {{--副页菜单模版--}}
    @include('default.layouts.index_vice_mune')
    {{--分站列表--}}
    @include('default.layouts.station')
    {{--banner--}}
    @if(!empty($recruitmentPic))
        <div class="banner" style=" background:url('{{asset($recruitmentPic)}}') no-repeat center"></div>
    @endif
    {{--end banner--}}

    {{--主要内容--}}
    <div class="main">
        <div class="wrapper">
            {{--招聘会链接--}}
            <div class="fairLinks">
                @if(count($newRecruitment)>0)
                    <ul>
                        @foreach($newRecruitment as $k =>$v)
                            <li id="list">
                                <div class="date @if($k == count($newRecruitment)-1) final @endif">
                                    <span>{{$v->hold_date}}</span>
                                    <span class="week">{{$v->week}}</span>
                                </div>
                                <div class="cont">
                                    <div class="info">
                                        <a href="{{url('job_fair_'.$v->id.'.html')}}" target="_blank">
                                            <p class="title">{{str_limit($v->job_title,44)}}</p>
                                            <p>举办时间：{{$v->hold_time}}<span class="pm">{{$v->hold_pm}}</span></p>
                                            <p>主办单位：{{str_limit($v->hold_unit,44)}}</p>
                                            <p>举办地点：{{str_limit($v->hold_address,44)}}</p>
                                            <p>联系电话：{{str_limit($v->phone,44)}}</p>
                                        </a>
                                    </div>
                                    <div class="connect">
                                        @if($v->exhibition == '1')
                                            <span class="ctop">
                                                <a data-id="{{$v->id}}" data-value="{{$v->exhibition}}" class="active">在线订展</a>
                                            </span>
                                        @else
                                            <span class="ctop">
                                                <a data-id="{{$v->id}}" data-value="{{$v->exhibition}}">关闭订展</a>
                                            </span>
                                        @endif
                                        @if($v->recruitment_type == '1')
                                            <span class="cbottom">
                                                <a href="{{url('job_fair_'.$v->id.'.html')}}" target="_blank">普通招聘会</a>
                                            </span>
                                        @else
                                            <span class="cbottom">
                                                <a href="{{url('job_fair_'.$v->id.'.html')}}" target="_blank"
                                                   class="active">校园招聘会</a>
                                            </span>
                                        @endif
                                    </div>
                                </div>
                            </li>
                        @endforeach
                    </ul>
                @else
                    <div class="">你还没有添加招聘会</div>
                @endif
            </div>
            {{--招聘会链接结束--}}

            {{--往期招聘--}}
            <div class="pastFair">
                <h3><span>往期招聘</span></h3>
                @if(count($oldRecruitment) > 0)
                    <dl>
                        <dt>
                        <ul>
                            <li class="col1">招聘会标题</li>
                            <li class="col2">举办时间</li>
                            <li class="col3">举办地点</li>
                            <li class="col4">主办单位</li>
                            <li class="col5">状态</li>
                        </ul>
                        </dt>
                        @foreach($oldRecruitment as $v)
                            <dd>
                                <ul>
                                    <li class="col1"><a href="{{url('job_fair_'.$v->id.'.html')}}"
                                                        target="_blank">{{str_limit($v->job_title,32)}}</a></li>
                                    <li class="col2">{{str_limit($v->hold_time,32)}}</li>
                                    <li class="col3">{{str_limit($v->hold_address,32)}}</li>
                                    <li class="col4">{{str_limit($v->hold_unit,32)}}</li>
                                    <li class="col5">已结束</li>
                                </ul>
                            </dd>
                        @endforeach
                    </dl>
                    {{--分页链接--}}
                    <div class="page_list">
                        {{$oldRecruitment->links()}}
                    </div>
                @else
                    <div class="nolist">
                        <span><img src="{{asset('default/images/index/bgpic.jpg')}}"></span>
                        <p>对不起,没有往期招聘会的记录!</p>
                    </div>
                @endif
            </div>
            {{--往期招聘结束--}}
        </div>
    </div>
    {{--主要内容结束--}}
@endsection
{{--首页js--}}
@section('footerjs')
    @parent
    <script type="text/javascript" src="{{asset('/default/js/jquery/jquery.form.js')}}"></script>
    <script type="text/javascript" src="{{asset('/default/js/jquery/jquery.validate.extend.js')}}"></script>
    <script>
        $(function(){
            $('.main').find('li').find('.ctop a').click(function(){
                var curr_id = $(this).attr('data-id');
                if($(this).attr('data-value') == '2'){
                    layer.msg('该招聘会已经关闭订展报名！', {time: 1500});
                }else{
                    var imgCode = "{{captcha_src('code')}}" + Math.random() + Math.random();
                    var src = "this.src='" + imgCode + "' + Math.random()";
                    var docSrc = "document.getElementById('imgCodes').src='" + imgCode + "' + Math.random()";
                    layer.open({
                        type: 1,
                        title: "招聘会报名",
                        move: false,
                        skin: 'layui-layer-rim', //加上边框
                        area: ['840px', '430px'], //宽高
                        content: '<div class="rightMain" style="padding:0px;"><div class="jobInfo">' +
                        '<div class="information"><span>你确定要报这个招聘会吗？</span></div>' +
                        '<form name="thisForm" onSubmit="return false" id="thisForm" method="post" >{{csrf_field()}}' +
                        '<input name="recruitment_id" type="hidden" value="' + curr_id + '" />' +
                        '<input name="com_uid" type="hidden" value="{{ $companyBasic->uid  or '0'}}" />' +
                        '<dl><dt><span class="caption">企业名称</span><span class="asterisk">*</span></dt><dd>' +
                        '<input type="text" name="company" id="company" value="{{ $companyBasic->company_name  or ''}}" placeholder="请输入企业名称" tip="请输入企业名称"/></dd><dd class="errinfo"></dd></dl>' +
                        '<dl><dt><span class="caption">联系人</span><span class="asterisk">*</span></dt><dd>' +
                        '<input type="text" name="contact_person" id="contact_person" value="{{ $companyBasic->contacts  or ''}}" placeholder="请输入联系人" tip="请输入联系人"/></dd><dd class="errinfo"></dd></dl>' +
                        '<dl><dt><span class="caption">联系电话</span><span class="asterisk">*</span></dt><dd>' +
                        '<input type="text" name="phone" id="phone" value="{{ $companyBasic->phone  or ''}}" placeholder="请输入联系电话" tip="请输入联系电话"/></dd><dd class="errinfo"></dd></dl>' +
                        '<dl><dt><span class="caption">验证码</span><span class="asterisk">*</span></dt>' +
                        '<dd><input type="text" name="code" id="code" value="" placeholder="请输入验证码" style="width:120px;" class="code" /></dd>' +
                        '<dd><img id="imgCodes" src="' + imgCode + '" onclick="' + src + '" /></dd>' +
                        '<dd class="change"><a onclick="' + docSrc + '">换一换</a></dd>' +
                        '<dd class="errinfo"></dd></dl>' +
                        '<dl style="margin-top:25px;"><dt></dt><dd><input name="sub" class="subs btn" type="submit" value="报名企业"></dd></dl>' +
                        '</div></div>'
                    });

                    //表单验证 使用jQuery Validate 插件进行验证
                    $('#thisForm').validate({
                        //指定使用什么标签标记错误。
                        errorElement: "span",
                        //一个函数，可以自定义错误放到哪里。
                        errorPlacement: function(error, element){
                            $(element).parents('dl').find(".errinfo").append(error);
                        },
                        //自定义错误消息
                        tipPlacement: function(element, tip){
                            $(element).parents('dl').find(".errinfo").append(tip);
                        },
                        //通过验证后执行的函数
                        success: function(label){
                            if(label.parents('dl').find('dd input').val() != ''){
                                label.text('ok!').addClass('success');
                            }
                        },
                        //未验证后执行的函数
                        highlight: function(element, errorClass){
                            $(element).closest("dl").find("dd.errinfo").find('span').removeClass('success');
                        },
                        ignore: "",
                        //js上面添加验证规则
                        rules: {
                            company: {
                                required: true
                            },
                            contact_person: {
                                required: true
                            },
                            phone: {
                                required: true
                            },
                            code: {
                                required: true,
                                remote: {
                                    url: '/common/ajax_code',                //后台处理程序
                                    type: "post",               //数据发送方式
                                    data: {                     //要传递的数据
                                        code: function(){ return $("#code").val();},
                                        _token: '{{csrf_token()}}'
                                    },
                                    dataType: "html",
                                    dataFilter: function(data, type){
                                        return (data == "true") ? true : false;
                                    }
                                }
                            }
                        },
                        //错误信息提示修改
                        messages: {
                            company: {
                                required: "请输入企业名称"
                            },
                            contact_person: {
                                required: "请输入联系人"
                            },
                            phone: {
                                required: "请输入联系电话"
                            },
                            code: {
                                required: "请输入验证码",
                                remote: $.validator.format('验证码错误，请重新输入')
                            }
                        },
                        submitHandler: function(form){
                            var queryString = $('#thisForm').formSerialize();
                            $.ajax({
                                url: '/signup',
                                dataType: "json",
                                data: queryString,
                                type: "POST",
                                beforeSend: function(){
                                    $('#thisForm').find('.subs').val('请稍候');
                                    $('#thisForm').find('.subs').attr('disabled', true);
                                    $('#thisForm').find('.subs').attr('readonly', true);
                                },
                                success: function(data){
                                    if(data.status == 0){
                                        layer.msg(data.msg, {icon: 6, time: 2000});
                                        location = '/job_fair';
                                    }else{
                                        layer.msg(data.msg, {time: 2000});
                                    }
                                },
                                error: function(data){
                                    var msgErr = '';
                                    var errors = $.parseJSON(data.responseText);
                                    $.each(errors, function(index, value){
                                        msgErr += value + ";<br>";
                                    });
                                    layer.msg(msgErr);
                                },
                                complete: function(){
                                    $('#thisForm').find('.subs').val('报名企业');
                                    $('#thisForm').find('.subs').removeAttr('disabled');
                                    $('#thisForm').find('.subs').removeAttr('disabled');
                                }
                            });
                        }
                    });
                }
            });
        });
    </script>
@endsection